package com.example.smartcitydemo.base

import android.content.IntentFilter
import android.os.Bundle
import android.os.PersistableBundle
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.example.smartcitydemo.ActivityManager
import com.example.smartcitydemo.receiver.LoginBroadCastReceiver

/**
 * @PACKAGE_NAME: com.example.smartcitydemo.base
 * @NAME: Caleb.F
 * @DATE: 2021/11/5 15:39
 * @Email: 191976283@qq.com
 */
abstract class BaseActivity<VB : ViewDataBinding>(@LayoutRes val layoutId: Int) :
    AppCompatActivity() {

    val TAG = this::class.java.simpleName

    val loginReceiver: LoginBroadCastReceiver by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
        LoginBroadCastReceiver()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ActivityManager.add(this)
        val contentView = DataBindingUtil.setContentView<VB>(this, layoutId)
        initView(contentView, savedInstanceState)
        initData()
        addObserver(contentView)
    }

    abstract fun addObserver(contentView: VB)

    abstract fun initData()

    abstract fun initView(contentView: VB, savedInstanceState: Bundle?)



    override fun onDestroy() {
        super.onDestroy()
        ActivityManager.remove(this)
    }
}